"""Build rdb"""


def scons():
    """Execute build"""
    Import('env', 'prereqs')

    if not prereqs.server_requested():
        return

    # raft
    denv = env.Clone()
    denv.SetOption('warn', 'no-missing-sconscript')
    denv.SConscript('raft/SConscript')

    # rdb-specific env
    denv = env.Clone()

    denv.require('argobots', 'protobufc')

    denv.AppendUnique(CPPPATH=[Dir('raft/include').srcnode()])
    denv.AppendUnique(LIBPATH=[Dir('raft/src')])

    # rdb
    rdb = denv.d_library('rdb',
                         ['rdb_util.c', 'rdb_path.c', 'rdb_layout.c',
                          'rdb_kvs.c', 'rdb_rpc.c', 'rdb_raft.c',
                          'rdb_tx.c', 'rdb.c', 'rdb_module.c'],
                         install_off="../..", LIBS=['raft'])
    denv.Install('$PREFIX/lib64/daos_srv', rdb)

    # tests
    if prereqs.test_requested():
        SConscript('tests/SConscript', exports='denv')


if __name__ == "SCons.Script":
    scons()
